<template>
  <div class="header">
    <div class="title-header">
      <div class="left-title">
        <i class="el-icon-s-fold" @click="isFoldChange()"></i>
      </div>
      <div
        class="right-title"
        @mouseleave="isOpenChange(false)"
      >
        <div class="top-right">
          <p style="cursor: pointer" @mouseenter="isOpenChange(true)">
            <i class="el-icon-user-solid"></i>Hi,{{ userData.name }}
          </p>
        </div>
        <div class="btm-right" v-if="isOpen">
          <p>个人中心</p>
          <p>用户管理</p>
          <p>系统设置</p>
          <p @click="exit()">退出登录</p>
        </div>
      </div>
    </div>
    <div class="connect-header">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/workbench' }"
          >工作台</el-breadcrumb-item
        >
        <el-breadcrumb-item
          :to="{ path: matched.path }"
          v-if="matched.path !== '/workbench'"
          >{{ matched.name }}</el-breadcrumb-item
        >
      </el-breadcrumb>
      <h1 v-if="matched.path === '/workbench'">您好,{{ userData.name }}</h1>
      <p v-if="matched.path === '/workbench'">您的角色: {{ userData.role }}</p>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      isOpen: false,
    };
  },
  computed: {
    userData() {
      let userInfo = JSON.parse(window.localStorage.getItem("userInfo")) || "";
      return userInfo;
    },
    matched() {
      let index = this.$route.matched.length - 1;
      return this.$route.matched[index];
    },
  },
  methods: {
    isOpenChange(boolean) {
      this.isOpen = boolean;
    },
    // 点击退出登录
    exit() {
      // 清空本地用户信息
      window.localStorage.removeItem("userInfo");
      // 跳转到登录页
      this.$router.push("/login");
    },
    // 左侧菜单的折叠切换
    isFoldChange() {
      this.$store.commit("home/SET_ISFOLD");
    },
  },
  components: {},
};
</script>
<style lang="scss" scoped>
.header {
  position: sticky;
  top: 0;
  margin-bottom: 5px;
  background-color: #fff;
  z-index: 10;
  box-shadow: 0 5px 5px #ccc;
  .title-header {
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30px;
    border-bottom: 1px solid #ccc;
    position: relative;
    .right-title {
      position: absolute;
      top: 0;
      right: 10px;
      width: 150px;
      height: 190px;
      // border: 1px solid red;
      .top-right {
        width: 150px;
        height: 70px;
        line-height: 70px;
        text-align: center;
      }
      .btm-right {
        position: absolute;
        top: 50px;
        right: 20px;
        width: 100px;
        height: 120px;
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        align-items: center;
        background-color: #fff;
        border: 1px solid #ccc;
        box-shadow: 0 3px 5px #ccc;
        p {
          width: 100%;
          height: 30px;
          line-height: 30px;
          text-align: center;
          margin-bottom: 3px;
        }
        p:hover {
          background-color: #ccc;
        }
      }
    }
  }
  .connect-header {
    padding: 0 30px;
    .el-breadcrumb {
      height: 60px;
      line-height: 60px;
    }
    h1 {
      height: 60px;
      line-height: 60px;
    }
    p {
      height: 60px;
      line-height: 60px;
    }
  }
}
</style>